/*
 * @Author: czy
 * @Date: 2021-04-23 16:00:20
 * @LastEditTime: 2021-07-15 21:16:13
 */
#include "stdio.h"
#include "stdlib.h"
#include "process.h"
#include "stdlib.h"

#define SLEEP(TIME) for (int i = 0; i < TIME; i++)\
                for (int j = 0; j < TIME; j++)

int tsk1(void)
{
    SLEEP(10000);
    printf("* \033[32m         tsk1-01          \033[0m*\n");
    SLEEP(10000);
    printf("* \033[32m         tsk1-02          \033[0m*\n");
    SLEEP(10000);
    printf("* \033[32m         tsk1-03          \033[0m*\n");
    return 0;
}

int tsk2(void)
{
    SLEEP(7000);
    printf("* \033[33m         tsk2-01          \033[0m*\n");
    SLEEP(7000);
    // printf("* \033[33m        tsk2-02         \033[0m*\n");
    printf("* \033[33mtry to raise an exception \033[0m*\n");
    int i = 0, j = 1;
    i = j / i;
    printf("* \033[33m         tsk2-03          \033[0m*\n");
    return 0;
}

int tsk5(void)
{
    SLEEP(9000);
    printf("* \033[36m         tsk5-01          \033[0m*\n");
    SLEEP(3000);
    printf("* \033[36m         tsk5-02          \033[0m*\n");
    SLEEP(100);
    printf("* \033[36m         tsk5-03          \033[0m*\n");
    exit(0);
    return 0;
}

void createTsk5(void)
{
    tskStart(createTsk(tsk5));
}

int tsk4(void)
{
    SLEEP(9000);
    printf("* \033[35m         tsk4-01          \033[0m*\n");
    cron(createTsk5, 4000, 1);
    SLEEP(3000);
    printf("* \033[35m         tsk4-02          \033[0m*\n");
    SLEEP(100);
    printf("* \033[35m         tsk4-03          \033[0m*\n");
    SLEEP(12000);
    printf("* \033[35m         tsk4-04          \033[0m*\n");
    SLEEP(3000);
    printf("* \033[35m         tsk4-05          \033[0m*\n");
    return 0;
}

int tsk3(void)
{
    SLEEP(12000);
    printf("* \033[34m         tsk3-01          \033[0m*\n");
    SLEEP(12000);
    printf("* \033[34m         tsk3-02          \033[0m*\n");
    tskStart(createTsk(tsk4));
    SLEEP(12000);
    printf("* \033[34m         tsk3-03          \033[0m*\n");
    SLEEP(12000);
    printf("* \033[34m         tsk3-04          \033[0m*\n");
    SLEEP(12000);
    printf("* \033[34m         tsk3-05          \033[0m*\n");
    return 0;
}

int main(void)
{
    tskStart(createTsk(tsk1));
    tskStart(createTsk(tsk2));
    tskStart(createTsk(tsk3));
    return 0;
}
